
/**
 * 获取组件ref
 * @param {VueComponentIns} 组件实例
 * @returns 组件ref
 */
// eslint-disable-next-line
export function useCompRef<T extends abstract new (...args: any) => any>(_: T) {
	return ref<InstanceType<T>>();
}

/**
 * 返回一个防抖的自定义ref
 * @param value ref的默认值
 * @param delay 延迟更新时间
 * @returns {customRef}
 */
export function useDebounceRef<T>(value: T, delay = 1000) {
	let timer;
	return customRef((track, trigger) => ({
		get() {
			track();
			return value;
		},
		set(newValue) {
			clearTimeout(timer);
			timer = setTimeout(() => {
				value = newValue;
				trigger();
			}, delay);
		}
	}));
}